/*
 * @Description: 
 * @Author: Aroma
 * @Date: 2024-09-27 09:32:27
 * @LastEditors: Aroma
 * @LastEditTime: 2024-09-27 15:14:45
 * @别瞎看: 你个无脑牛马

/**
 * Test02List
 */

import java.util.ArrayList;
import java.util.List;

public class Test02List {

    public static void main(String[] args) {
        //创建一个List类型的对象
        List<String> list = new ArrayList<>();
        //添加元素
        list.add("hello1");
        list.add("hello1");
        list.add("hello2");
        list.add("hello3");
        list.add("hello1");
        //输出集合
        System.out.println(list);
        System.out.println(list.size());
        System.out.println(list.get(0));
        //System.out.println(list.get(5));//索引越界
        
        System.out.println(list);
        //修改
        System.out.println(list.set(0,"hello0"));
        System.out.println(list);
        //插入
        list.add(0, "hello00");
        System.out.println(list);
        System.out.println(list.size());
        list.add(5,"hello5");
        System.out.println(list);
        System.out.println(list.size());
        //删除
        boolean flag=list.remove("hello1");
        System.out.println(flag);
        System.out.println(list);
        System.out.println(list.size());
        
        String s0=list.remove(0);
        System.out.println(s0);
        list.add("hello1");
        list.add("hello2");
        list.add("hello3");
        list.add("hello1");
        System.out.println(list);
        System.out.println(list.size());
        //查找
        int result=list.indexOf("hello1");
        //索引从0开始
        System.out.println(result);
        //最后一个
        result=list.lastIndexOf("hello1");
        //索引从0开始
        System.out.println(result);
        //截取
        List<String> subList = list.subList(0, 3);
        System.out.println(subList);
        System.out.println(subList.size());
    }
}